package com.example.taobao

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.Editable
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.util.Log
import kotlinx.android.synthetic.main.newaddress.*
import okhttp3.FormBody
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.lang.Exception
import java.net.URLEncoder
import kotlin.concurrent.thread

class Newaddress : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.newaddress)
        val prefs = getSharedPreferences("data",Context.MODE_PRIVATE)
        val username = prefs.getString("name","未登录")
        btn_save.setOnClickListener {
            thread {
                try {
                    val client = OkHttpClient()
                    val requestBody = FormBody.Builder()
                        .add("name", URLEncoder.encode(et_shouhuoren.text.toString(), "utf-8"))
                        .add(
                            "phonenumber",
                            URLEncoder.encode(et_Mobile.text.toString(), "utf-8")
                        )
                        .add("suozaidiqu", URLEncoder.encode(tv_city1.text.toString(), "utf-8"))
                        .add(
                            "xiangxidiz",
                            URLEncoder.encode(et_xiangxidizhi.text.toString(), "utf-8")
                        )
                        .add("username", URLEncoder.encode(username, "utf-8"))
                        .build()
                    val request = Request.Builder()
                        .url("http://192.168.43.140:8080/aaa_war_exploded/addaddress.jsp")
                        .post(requestBody)
                        .build()
                    val respone = client.newCall(request).execute()
                    val responeData = respone.body?.string()
                } catch (e: Exception) {
                    e.printStackTrace()
                }
                finish()
            }
        }
    }
}